package flexexamples.logging
{
	import org.as3commons.logging.LogLevel;
	import org.as3commons.logging.impl.DefaultLogger;
	import org.as3commons.logging.util.MessageUtil;

	public class RemoteLogger extends DefaultLogger
	{
		protected var _level:uint;
		
		protected var remote:Object;
		
		public function RemoteLogger(name:String, remote:Object)
		{
			super(name);
			this.remote = remote;
		}
		
		 override protected function log(level:uint, message:String, params:Array):void {
                if (level >= this._level) {
                        // add datetime
                        var msg:String = "[" + new Date().toString() + "]";
                        
                        // add name and params
                        msg += "[" + name + "]";
                        
                        // add message
                        msg += " - " + MessageUtil.toString(message, params);
                        
                        var logLevel:String = LogLevel.toString(level);
                        trace("["+logLevel+"] "+msg);
                        remote.log(logLevel, msg);
                }
        }
	}
}